/* eslint-disable prettier/prettier */
/*
直接更新 state 的多个方法的对象
*/
export default {
  // 保存token信息
  SET_TOKEN(state, {
    token
  }) {
    state.token = token;
  },

  // 设置认证状态
  SET_LOGIN_STATUS(state, bool) {
    state.loginStatus = bool;
  },

  //发送后立即存储sendInParams
  SETSENDINPARAMS(state, {
    params
  }) {
    state.sendInParams = params.sendParams;
  },
  SETSENDINPARAMS_OTHER(state, {
    params
  }) {
    state.sendInParams = params;
  },

  // 获取发送和接收数据
  GETQUERYINFO(state, {
    params,
    resData
  }) {
    // state.sendInParams = params;
    state.sendOutParams = resData;
    // state.httpsPageFlag = 1;

    // state.stateIp = params.ip;
    // state.statePort = params.port;
    // state.stateUser = params.user;
    // state.stateServerIp = params.serverIp;
    // state.stateServerPort = params.serverPort;
    // state.statePubName = params.pubName;
    // state.stateAuthInfo = params.authInfo;

    // state.sendOutParams.analyses = resData.analyses.replace(/↵/g,"\n");
  },
  // VideoTransBEGIN 获取发送和接收数据
  GETQUERYINFO_VTBEGIN(state, {
    params,
    resData
  }) {
    // state.sendInParams = params.sendParams;
    state.sendOutParams = resData;
    state.httpsPageFlag = 1;
    

    // state.stateIp_vTBegin = params.ip;
    // state.statePort_vTBegin = params.port;
    // state.stateUser_vTBegin = params.user;
    // state.stateServerIp_vTBegin = params.serverIp;
    // state.stateServerPort_vTBegin = params.serverPort;
    // state.statePubName_vTBegin = params.pubName;
    // state.stateAuthInfo_vTBegin = params.authInfo;

    // state.sendOutParams.analyses = resData.analyses.replace(/↵/g,"\n");
  },
  // VideoTransFinish 获取发送和接收数据
  GETQUERYINFO_VTFINISH(state, {
    params,
    resData
  }) {
    // state.sendInParams = params.sendParams;
    state.sendOutParams = resData;
    state.httpsPageFlag = 1;

    // state.stateIp_vTBegin = params.ip;
    // state.statePort_vTBegin = params.port;
    // state.stateUser_vTBegin = params.user;
    // state.stateVideoType_vTFinish = params.videoType;

    // state.sendOutParams.analyses = resData.analyses.replace(/↵/g,"\n");
  },
  // ptzControl 获取发送和接收数据
  GETQUERYINFO_PTZCONTROL(state, {
    params,
    resData
  }) {
    // state.sendInParams = params.sendParams;
    state.sendOutParams = resData;
    state.httpsPageFlag = 1;

    // state.stateIp_vTBegin = params.ip;
    // state.statePort_vTBegin = params.port;
    // state.stateUser_vTBegin = params.user;
    state.stateAction_ptzControl = params.sendParams.action;
    state.stateStep_ptzControl = params.sendParams.step;

    // state.sendOutParams.analyses = resData.analyses.replace(/↵/g,"\n");
  },

  // 获取插入流媒体地址结果
  ADDURLINFO(state, {
    resData
  }) {
    state.addReturnMsg = resData.msg;
    console.log("state.addReturnMsg:" + state.addReturnMsg);
  },
  // 获取重载流媒体地址结果
  RELOADURLINFO(state, {
    resData
  }) {
    state.reloadReturnMsg = resData.msg;
    console.log("state.reloadReturnMsg:" + state.reloadReturnMsg);

  },
  // 获取重载流媒体地址结果
  EMPTYURLINFO(state, {
    resData
  }) {
    state.emptyReturnCode = resData.code;
    console.log("state.emptyReturnCode:" + state.emptyReturnCode);

  },
  // 获取开始测试返回结果
  STARTTESTURLINFO(state, {
    resData
  }) {
    state.startTesteturnMsg = resData.msg;
    console.log("state.startTesteturnMsg:" + state.startTesteturnMsg);

  },

  // 获取摄像头数据
  GETCAMERANUM(state, {
    resData
  }) {
    // var str = "";
    // for (var i = 0; i < resData.cameraNum.length; i++) {
    //   str += resData.cameraNum[i].split(",")[0];
    // }
    // //去掉最后一个逗号(如果不需要去掉，就不用写)
    // if (str.length > 0) {
    //   str = str.substr(0, str.length - 1);
    // }

    // console.log("camera信息111：", resData);

    // 截取cameraNum中的,前英文字符串
    // var str = "";
    // var splits = new Array(); //定义一数组 
    // for (var i = 0; i < resData.cameraNum.length; i++) {
    //   str = resData.cameraNum[i].split(",")[0];
    //   splits[i] = str;
    // }
    // state.cameraList = splits;
    state.cameraList = resData.cameraNums;
  
  },

  // 获取token数据
  GETTOKENNUM(state, {
    resData
  }) {
    // console.log("camera信息111：", resData);

    // 截取cameraNum中的,前英文字符串
    // var str = "";
    // var splits = new Array(); //定义一数组 
    // for (var i = 0; i < resData.cameraNum.length; i++) {
    //   str = resData.cameraNum[i].split(",")[0];
    //   splits[i] = str;
    // }
    // console.log("str:",str)
    // console.log("tyeof str:",typeof(str))
    // console.log("splits:",splits)
    // console.log("tyeof splits:",typeof(splits))

    state.curToken = resData.cur_token;
    // console.log("curToken111：", state.curToken);
    // console.log("camera信息222[0]：", state.cameraList[0]);
  },

  // 获取deviceUsers厂商列表数据
  GETDEVICEUSERS(state, {
    resData
  }) {
    // console.log("DEVICEUSERS信息：", resData);

    state.deviceUsersList = resData.users;
    // console.log("deviceUsersList111：", state.deviceUsersList);
  },

  //获取厂商camerNums列表
  GETUSERPLAYERCAMERNUMS(state, {
    resData
  }) {
    // console.log("USERPLAYERCAMERNUMS信息：", resData);

    state.nowCamerNums = resData.cameraNums;
    // console.log("state.nowCamerNums：", state.nowCamerNums);
  },

  //获取厂商online的流id
  GETONLINESTREAMID(state, {
    resData
  }) {
    // console.log("GETONLINESTREAMID信息：", resData);
    state.streamsList = resData.streams.Streams;
  },

  //根据online的流id获取对应url
  GETSTREAMURLBYID(state, {
    resData,
    params
  }) {
    // state.playStreamUrlList.push(resData.url);
    let key = params.streamId;
    let value = resData.url;
    state.playStreamUrlList[key] = value;
  },

  CHANGETOKENSTATEVAL(state, {
    params
  }) {
    state.curToken = params;
  },

  QUERYTESTITEMLIST(state, {
    resData
  }) {
    state.testItemList = resData.msg;
  },
  QUERYTESTRESULTLIST(state, {
    resData
  }) {
    state.testResultList = resData.msg;
    console.log("state.testResultList::", state.testResultList)
  },

  QUERYTASKINFO(state, {
    data
  }) {
    state.taskInfo = data;
  },
  QUERYMONITORRESULTINFO(state, {
    resData
  }) {
    state.resultInfo.summary = resData.summary ? resData.summary : [];
    state.resultInfo.details = resData.details ? resData.details.map((item, index) => {
      return {
        id: index,
        ...item
      }
    }) : [];
  },

  CHANGEITEMTOTAL(state, {
    total
  }) {
    state.itemTotalNumber = total;
    console.log("state.itemTotalNumber:", state.itemTotalNumber)
  },

  QUERYCAMERASTATUS(state, {
    resData
  }) {
    state.cameraStatus = {
      ...resData
    };
  },

  GETDEVICEUSERSDEFINITELYINFO(state, { resData }) {
    state.beginExsitInfo.ip = resData.ip;
    state.beginExsitInfo.port = resData.port;
    state.beginExsitInfo.user = resData.sywg_username;
  },

  CHANGEFIRSTHTTPSPAGEFLAG(state, {val}) { //修改切换tab进入https信令页面的flag
    state.httpsPageFlag = val;
  },
};